package com.zhoug.json2app;

import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.zhoug.json2.GsonUtils;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends MyBaseActivity {

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_main;
    }

    @Override
    protected void findViews() {

    }

    @Override
    protected void onCreate1(Bundle savedInstanceState) {
        GsonUtils gsonUtils = GsonUtils.getDefault();
        List<TestData> list=new ArrayList<>();
        TestData testData=new TestData();
        testData.setAge(12);
        testData.setName("张三");
        testData.setManager(false);
        list.add(testData);
        testData=new TestData();
        testData.setAge(12);
        testData.setName("管理员");
        testData.setManager(true);
        list.add(testData);

        Log.d(TAG, "testData:"+ gsonUtils.toJson(testData));
        String jsonList = gsonUtils.toJson(list);
        Log.d(TAG, "list:"+ jsonList);
        Log.d(TAG, "fromJson testData:"+ gsonUtils.fromJson(gsonUtils.toJson(testData),TestData.class));
        Log.d(TAG, "fromJsonTypeToken list:"+ gsonUtils.fromJsonList(jsonList,new TypeToken<List<TestData>>(){}));
        Log.d(TAG, "fromJsonType list:"+ gsonUtils.fromJsonList(jsonList,new TypeToken<List<TestData>>(){}.getType()));
        Log.d(TAG, "fromJsonClass list:"+ gsonUtils.fromJsonList(jsonList,TestData.class));


    }


}